//
//  NewFeatureController.m
//  微博
//
//  Created by 沈艳男 on 15/11/28.
//  Copyright © 2015年 沈艳男. All rights reserved.
//

#import "NewFeatureController.h"
#import "NewFeatureCell.h"

@interface NewFeatureController ()

@end

@implementation NewFeatureController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.collectionView registerClass:[NewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
}

- (instancetype)init
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self = [super initWithCollectionViewLayout:flowLayout];
    flowLayout.itemSize = self.view.bounds.size;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    return self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld", indexPath.item + 1]];
    
//    cell.backgroundColor = (indexPath.item % 2) ? [UIColor redColor]: [UIColor blueColor];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
    // 获取当前cell的索引
    NSIndexPath *didIndexPath = [[self.collectionView indexPathsForVisibleItems] lastObject];
    if (didIndexPath.item == 3) {
        // 根据cell的索引获取cell
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:didIndexPath];
        [(NewFeatureCell *)cell showStartButton];
    }

}

//
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
    // 获取当前cell的索引
    NSIndexPath *didIndexPath = [[self.collectionView indexPathsForVisibleItems] lastObject];
    if (didIndexPath.item == 3) {
        // 根据cell的索引获取cell
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:didIndexPath];
        [(NewFeatureCell *)cell hiddenstartButton];
        NSLog(@"%ld", (long)didIndexPath.item);
    }
}
@end
